﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace MengLin.OOP.DesignPattern.TemplateMethod.Interest
{
    public abstract class BaseUser
    {
        /// <summary>
        /// 查询利息
        /// 通用处理流程：检查用户==>查询余额==>计算利息==>展示信息
        /// </summary>
        /// <param name="id"></param>
        /// <param name="userName"></param>
        /// <param name="password"></param>
        public void QueryInterest(int id, string userName, string password)
        {
            //定义流程
            //1.检查用户-通用逻辑
            if (CheckUser(id, userName, password))
            {
                //2.查询余额-通用逻辑
                decimal currBalance = QueryBalance();
                //3.计算利息-不同的逻辑
                decimal interest = CalculateInterest(currBalance);
                //4.展示信息-不同的逻辑-钩子方法
                Show(userName,currBalance, interest);
            }
        }

        /// <summary>
        /// 检查用户
        /// </summary>
        /// <param name="id"></param>
        /// <param name="userName"></param>
        /// <param name="password"></param>
        /// <returns></returns>
        private bool CheckUser(int id,string userName,string password)
        {
            return true;
        }

        /// <summary>
        /// 得到余额
        /// </summary>
        /// <returns></returns>
        public decimal QueryBalance()
        {
            return new Random().Next(1000, 10000);
        }

        /// <summary>
        /// 计算利息
        /// </summary>
        /// <param name="currBalance">余额</param>
        /// <returns></returns>
        public abstract decimal CalculateInterest(decimal currBalance);

        /// <summary>
        /// 展示余额和利息--钩子方法
        /// </summary>
        /// <param name="currBalance">余额</param>
        /// <param name="interest">利息</param>
        /// <returns></returns>
        public virtual void Show(string userName, decimal balance,decimal interest)
        {
            Console.WriteLine($"尊敬的用户，{userName}您好：\n您的余额为：{balance},计算后的利息为：{interest}");
        }
    }
}
